﻿using STHPMS1.Common.C_Enum;
using STHPMS1.ICore.I_Serv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using STHPMS1.Common.C_Extension;
using STHPMS1.ICore.I_Entity.Stmpms1;
using STHPMS1.Common.C_Entity.Stmpms1;

namespace STHPMS1.BLL.B_Serv
{
    public class ModelCalculateFactoryService : IModelCalculateFactoryService
    {
        public IModelCalculateService Load(STHPMS1.ICore.I_Core.IScene scene,string modelId)
        {
            if(scene==null)throw new Exception("scene is null on ModelCalculateFactoryService");
            IDm_Origpv_Reg model=scene.Dal.Sthpms1.SingleById<Dm_Origpv_Reg>(modelId);
            if(model==null)throw new Exception("model is not exitst: "+modelId);
            IEnumerable<IDm_Origpv_Param> Coefficient = scene.Dal.Sthpms1.Select<Dm_Origpv_Param>(p => p.Modelid == modelId);

            IModelCalculateService equation = null;
            if(model.Formulatype==FormulaEnum.Equation1.GetEnumValue())
            {
                equation = CreateEquation1();
            }
            else if (model.Formulatype == FormulaEnum.Equation2.GetEnumValue())
            {
                equation = CreateEquation2();
            }
            else if (model.Formulatype == FormulaEnum.Equation3.GetEnumValue())
            {
                equation = CreateEquation3();
            }
            equation.Model = model;
            equation.Coefficient = Coefficient;

            return equation;
        }


        public IEquation1Service CreateEquation1()
        {
            return new Equation1Service();
        }

        public IEquation2Service CreateEquation2()
        {
            return new Equation2Service();
        }

        public IEquation3Service CreateEquation3()
        {
            return new Equation3Service();
        }
    }
}
